package com.framework.service.impl;


import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.framework.dao.ter.TerRebackMerLogDao;
import com.framework.entity.sys.SysAgent;
import com.framework.entity.ter.TerMerchantReport;
import com.framework.entity.ter.TerRebackMerLog;
import com.framework.page.PageUtils;
import com.framework.service.MerchantService;
import com.framework.service.TerRebackMerLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author wq
 */
@Service("terRebackMerLogService")
public class TerRebackMerLogServiceImpl extends ServiceImpl<TerRebackMerLogDao,TerRebackMerLog> implements TerRebackMerLogService {

    @Autowired
    private MerchantService merchantService;

    @Override
    public void addNewRecord(String sn, Long rebackId) {
        TerMerchantReport report = merchantService.queryMerchantBySn(sn);

        TerRebackMerLog log=new TerRebackMerLog();

        log.setSn(sn);
        log.setRebackId(rebackId);
        log.setRebackDate(new Date());
        log.setReportDate(report.getCreateDate());
        log.setMerchantName(report.getMerchantName());
        log.setDeptId(report.getDeptId());
        log.setPhone(report.getPhone());
        log.setReportId(report.getAgentId());
        log.setTerminalType(report.getTerminalType());

        insert(log);

    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Integer currPage = Integer.valueOf(params.get("page").toString());
        Integer pageSize = Integer.valueOf(params.get("limit").toString());
        params.put("start", (currPage - 1) * pageSize);
        params.put("limit", pageSize);
        List<Map<String, Object>> terlist = baseMapper.queryList(params);
        Integer totalCount = baseMapper.queryCount(params);
        return new PageUtils(terlist, totalCount, pageSize, currPage);
    }
}
